# coding=utf-8
# 全世界最帅的帅哥
from elasticsearch_dsl import Document, Long, Text, Integer, Keyword, Date
from elasticsearch_dsl import connections

from ysgg1_club_comment.es_client import es

connections.create_connection(hosts=['http://121.40.187.211:9200/'])


class EsSubjectFields(Document):
    index = 'subject_index'  # 指定索引名

    doc_id = Long()

    subject_id = Long()

    subject_name = Text(analyzer='ik_smart')

    subject_answer = Text(analyzer='ik_smart')

    subject_type = Integer()

    create_user = Keyword()

    create_time = Date()

    class Index:
        name = 'subject_index'  # 索引名称，必须与 index 属性一致
        settings = {
            "number_of_shards": 1,  # 分片数
            "number_of_replicas": 1  # 副本数
        }


# 检查索引是否存在

if not es.indices.exists(index=EsSubjectFields.index):
    # 创建索引
    EsSubjectFields.init()
